// JavaScript Document
function startMove(obj,json,endFn){
		clearInterval(obj.timer);
		obj.timer = setInterval(function(){
			var bBtn = true;
			for(var attr in json){
				var iCur = 0;
				if(attr == 'opacity'){
					if(Math.round(parseFloat(getStyle(obj,attr))*100)==0){
					iCur = Math.round(parseFloat(getStyle(obj,attr))*100);
					}
					else{
						iCur = Math.round(parseFloat(getStyle(obj,attr))*100) || 100;
					}
				}
				else{
					iCur = parseInt(getStyle(obj,attr)) || 0;
				}
				var iSpeed = (json[attr] - iCur)/8;
			iSpeed = iSpeed >0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
				if(iCur!=json[attr]){
					bBtn = false;
				}
				if(attr == 'opacity'){
					obj.style.filter = 'alpha(opacity=' +(iCur + iSpeed)+ ')';
					obj.style.opacity = (iCur + iSpeed)/100;
				}
				else{
					obj.style[attr] = iCur + iSpeed + 'px';
				}
			}

			if(bBtn){
				clearInterval(obj.timer);
				if(endFn){
					endFn.call(obj);
				}
			}

		},30);
	}
	function getStyle(obj,attr){
		if(obj.currentStyle){
			return obj.currentStyle[attr];
		}
		else{
			return getComputedStyle(obj,false)[attr];
		}
	}

window.onload = function(){
// 专家切换
var slidePos = document.querySelector('.slide-pos');
var slideDl = slidePos.getElementsByTagName('li');
var posIndex = document.querySelector('.pos-index');
var posA = posIndex.getElementsByTagName('a');
var slideLen = slideDl.length;
var slideDlW = slideDl[0].clientWidth;
var slideDlAll = slideDlW*slideLen;
var sNum = 0;
var sNum2 = 0;

slidePos.style.width = slideDlAll + 'px';
for(var i=0;i<slideLen;i++){
	posA[i].index = i;
	posA[i].onmouseover = function(){

		if(this.index == 0){
			slideDl[0].style.position = 'static';
		}
		sNum = this.index;
		sNum2 = this.index;
		for(var i=0;i<slideLen;i++){
			posA[i].className = '';
		}
		this.className = 'active';
		startMove(slidePos,{left:-this.index*slideDlW});
		startMove(slideDl[this.index],{opacity:100});
		for(var i=0;i<slideLen;i++){
			if(this.index!=i){
				startMove(slideDl[i],{opacity:0});
			}
		}
	}
	slidePos.onmouseover = function(){
		 clearInterval(slidePos.slidePosTimer);
	}
	slidePos.onmouseout = function(){
		slidePos.slidePosTimer = setInterval(autoMove,3000);
	}
	posIndex.onmouseover = function(){
		 clearInterval(slidePos.slidePosTimer);
	}
	posIndex.onmouseout = function(){
		slidePos.slidePosTimer = setInterval(autoMove,3000);
	}
}
slidePos.slidePosTimer = setInterval(autoMove,3000);
function autoMove(){
	sNum2++;
	if(sNum == slideLen-1){
		sNum = 0;
		slideDl[0].style.position = 'relative';
		slideDl[0].style.left = slideLen*slideDlW + 'px';
	}else{
		sNum++;
	}

	for(var i=0;i<slideLen;i++){
		posA[i].className = '';
	}
	posA[sNum].className = 'active';

	startMove(slidePos,{left:-sNum2*slideDlW},function(){
		if(sNum == 0){
			slideDl[0].style.position = 'static';
			slideDl[0].style.left = 0 +'px';
			slidePos.style.left=0;
			sNum2=0;
		}
	});
	startMove(slideDl[sNum],{opacity:100});
	for(var i=0;i<slideLen;i++){
		if(sNum!=i){
			startMove(slideDl[i],{opacity:0});
		}
	}
}
}


// fixed
var sideWrap = document.querySelector('.side-wrap-main');
var navWrap = document.querySelector('.nav-wrap-main');
var sWrap = document.querySelector('.s-wrap');
sideWrap.tempT = getOffsetTop(sideWrap,true).top;
navWrap.tempT = getOffsetTop(navWrap,true).top;
sWrap.tempT = getOffsetTop(sWrap,true).top+sWrap.offsetHeight;

window.onscroll = function(){
	sWrap.tempT = getOffsetTop(sWrap,true).top+sWrap.offsetHeight;
	slideOpacity(sideWrap,93);
	slideOpacity(navWrap,0);
}
function slideOpacity(target,initialValue){

	var scropT = GetPageScroll() + initialValue;
	if(scropT > target.tempT){
		target.style.position='fixed';
		target.style.top= 0 + initialValue +'px';
	}
	if(scropT < target.tempT){
		target.style.position='static';
	}
	if(scropT > sWrap.tempT - target.offsetHeight){
		 startMove(target,{opacity:0},function(){
		 	target.style.height = 0;
		 	target.style.overflow = 'hidden';
		 });
		}else{
		 target.style.overflow = 'visible';
		 target.style.height = 'auto';
		 startMove(target,{opacity:100});
		}
	function GetPageScroll() {
		var y;
		if(window.pageYOffset) {
		// all except IE
		y = window.pageYOffset;
		} else if(document.documentElement
		&& document.documentElement.scrollTop) {
		// IE 6 Strict
		y = document.documentElement.scrollTop;
		} else if(document.body) {
		// all other IE
		y = document.body.scrollTop;
		}
		return y;
		}
}

function getOffsetTop(obj,flag) {
	if(flag){
		var t = obj.offsetTop + parseInt(getStyle(obj,'borderTopWidth'));
		var l = obj.offsetLeft + parseInt(getStyle(obj,'borderLeftWidth'));
	while (obj = obj.offsetParent) {
		t += obj.offsetTop + parseInt(getStyle(obj,'borderTopWidth'));
		l += obj.offsetLeft + parseInt(getStyle(obj,'borderLeftWidth'));
	}
	}else{
		t = obj.offsetTop + parseInt(getStyle(obj,'borderLeftWidth'));
		l = obj.offsetLeft + parseInt(getStyle(obj,'borderLeftWidth'));
	}
	return {top:t,left:l};
}


tabMe('.tab-menu1','.tab-content1','flipInY');
function tabMe(tabMenu,tabContent,tabxg){
var tabMenu = document.querySelector(tabMenu);
var tabContent = document.querySelector(tabContent);
var tabMenuA = tabMenu.querySelectorAll('li');
var tabContentUl = tabContent.querySelectorAll('.tab-panel');
var tabLen = tabMenuA.length;
var oldClass = tabContentUl[0].className;
for(var i=0;i<tabLen;i++){
tabMenuA[i].index = i;
tabMenuA[i].onmouseover = function(){
for(var i=0;i<tabLen;i++){
tabContentUl[i].className = oldClass;
tabContentUl[i].style.display = 'none';
tabMenuA[i].className = '';
}
this.className = 'active';
tabContentUl[this.index].style.display = 'block';
tabContentUl[this.index].className = oldClass + ' ' + 'animated' + ' ' + tabxg;
for(var i=0;i<tabLen;i++){
    for(var j=3;j<tabContentUl[i].querySelectorAll('li').length-1;j++){
    tabContentUl[i].querySelectorAll('li')[j].style.display = 'none';
    }
    }
    }
    }
    }
    readMore();
    function readMore(){
    var readMore = document.querySelectorAll('.s12-p3');
    var rmTabContent = document.querySelector('.tab-content1');
    var rmTabPanel = rmTabContent.querySelectorAll('.tab-panel');
    var rmTabPanelLiLen = rmTabPanel[0].querySelectorAll('li').length;
    var rmBtn = document.querySelectorAll('.s12-p3');
    var readMoreLen = readMore.length;
    for(var i=0;i<readMoreLen;i++){
    rmBtn[i].index = i;
    rmBtn[i].onclick = function(){
    for(var i=0;i<rmTabPanelLiLen;i++){
    rmTabPanel[this.index].querySelectorAll('li')[i].style.display = 'block';
    }
    for(var i=0;i<readMoreLen;i++){
    if(i==this.index){
    rmBtn[this.index].style.display = 'none';
    }else{
    rmBtn[i].style.display = 'block';
    }
    }
    for(var i=3;i<rmTabPanelLiLen;i++){
    rmTabPanel[this.index].querySelectorAll('li')[i].className = 'animated bounceIn';
    }
    }
    }
    }